
from rest_framework.viewsets import ModelViewSet

from goods.models import SKU
from meiduo_admin.serializers.sku import SKUSerializer
from meiduo_admin.utils import PageNum


class SKUModelViewSet(ModelViewSet):
    """SKU表管理"""
    # queryset = SKU.objects.all().order_by('id')
    serializer_class = SKUSerializer
    # 分页类
    pagination_class = PageNum

    def get_queryset(self):
        # 提取keyword
        keyword = self.request.query_params.get('keyword')

        if keyword == '' or keyword is None:
            return SKU.objects.all().order_by('id')
        else:
            return SKU.objects.filter(name__contains=keyword).order_by('id')
